package com.estore.model;

import java.io.Serializable;
import java.util.Objects;

/**
 * 用户实体类（包含管理员和普通用户）
 */
public class User implements Serializable {
    private static final long serialVersionUID = 1L;

    // 角色枚举
    public enum Role {
        ADMIN, USER
    }

    private String username;    // 用户名（唯一）
    private String password;    // 密码（实际项目需加密存储）
    private Role role;          // 角色

    public User(String username, String password, Role role) {
        this.username = username;
        this.password = password;
        this.role = role;
    }

    // Getters and Setters
    public String getUsername() { return username; }
    public void setUsername(String username) { this.username = username; }
    public String getPassword() { return password; }
    public void setPassword(String password) { this.password = password; }
    public Role getRole() { return role; }
    public void setRole(Role role) { this.role = role; }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        User user = (User) o;
        return Objects.equals(username, user.username);
    }

    @Override
    public int hashCode() {
        return Objects.hash(username);
    }
}